package com.achen.routing;

import com.achen.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * @author achen
 * @create 2021-07-27 20:58
 */
public class Provider {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMQUtils.getConnection();

        Channel channel = connection.createChannel();

        //将通道声明指定交换机
        //参数一：交换机名称
        //参数二：交换机类型 fanout：广播
        channel.exchangeDeclare("logs_direct", "direct");

        //通过交换机发送消息
        String routingKey = "error";
        channel.basicPublish("logs_direct", routingKey, null, ("这是direct模型发布的基于route key：[" + routingKey + "]发送的消息").getBytes());

        RabbitMQUtils.closeConnectionAndChannel(channel, connection);
    }
}
